package org.example;

import org.example.goods.Goods;
import org.example.shopping.ShoppingCart;
import org.example.supermarket.Supermarket;

import java.math.BigDecimal;

public class Main {

    //超市
    private static Supermarket supermarket = new Supermarket();
    public static void main(String[] args) {
        ShoppingCart shoppingCart = new ShoppingCart();
        //添加苹果和草莓商品
        Goods apple = new Goods("苹果",new BigDecimal("8"));
        Goods strawberry = new Goods("草莓",new BigDecimal("13"));
        supermarket.addGoods("001",apple);
        supermarket.addGoods("002",strawberry);
        //添加2斤苹果和3斤草莓
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("2"),supermarket.getGoodsByNo("001"));
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("3"),supermarket.getGoodsByNo("002"));
        System.out.println("第一题购买2斤苹果和3斤草莓需要："+shoppingCart.getTotalPrice()+"元");
        //总价格清空为0
        shoppingCart.resetCart();

        //添加芒果商品
        Goods mango = new Goods("芒果",new BigDecimal(20));
        supermarket.addGoods("003",mango);
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("2"),supermarket.getGoodsByNo("001"));
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("3"),supermarket.getGoodsByNo("002"));
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("4"),supermarket.getGoodsByNo("003"));
        System.out.println("第二题购买2斤苹果和3斤草莓和4斤芒果需要："+shoppingCart.getTotalPrice()+"元");
        //总价格清空为0
        shoppingCart.resetCart();

        //草莓打八折
        supermarket.setDiscount("002",new BigDecimal("0.8"));
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("2"),supermarket.getGoodsByNo("001"));
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("3"),supermarket.getGoodsByNo("002"));
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("4"),supermarket.getGoodsByNo("003"));
        System.out.println("第三题购买2斤苹果和3斤草莓和4斤芒果（草莓打八折）需要："+shoppingCart.getTotalPrice()+"元");
        //总价格清空为0
        shoppingCart.resetCart();

        //继续增加活动，满100元减10元
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("2"),supermarket.getGoodsByNo("001"));
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("3"),supermarket.getGoodsByNo("002"));
        shoppingCart.addGoodsToShoppingCart(new BigDecimal("4"),supermarket.getGoodsByNo("003"));
        BigDecimal totalPrice = supermarket.computePrice(new BigDecimal("100"),new BigDecimal("10"),shoppingCart.getTotalPrice());
        System.out.println("第四题购买2斤苹果和3斤草莓和4斤芒果（草莓打八折，满100减10元）需要："+totalPrice+"元");

    }
}
